package com.ruoyi.system.service.impl;

import java.util.List;
import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.RoomMapper;
import com.ruoyi.system.domain.Room;
import com.ruoyi.system.service.IRoomService;

/**
 * 会议室管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@Service
public class RoomServiceImpl implements IRoomService 
{
    @Autowired
    private RoomMapper roomMapper;

    /**
     * 查询会议室管理
     * 
     * @param roomId 会议室管理主键
     * @return 会议室管理
     */
    @Override
    public Room selectRoomByRoomId(Long roomId)
    {
        return roomMapper.selectRoomByRoomId(roomId);
    }

    /**
     * 查询会议室管理列表
     * 
     * @param room 会议室管理
     * @return 会议室管理
     */
    @Override
    public List<Room> selectRoomList(Room room)
    {
        return roomMapper.selectRoomList(room);
    }

    @Override
    public List<Room> selectRoomListBySearch(Room room) {
        if(room.getRoomAddress()==null)room.setRoomAddress("");
        if(room.getStatus()=="" || room.getStatus()==null){
            return roomMapper.selectRoomListBySearch(room.getRoomAddress(),room.getRoomMax(),"0","3");
        }else {
            return roomMapper.selectRoomListBySearch(room.getRoomAddress(),room.getRoomMax(),"3",room.getStatus());
        }
    }

    /**
     * 新增会议室管理
     * 
     * @param room 会议室管理
     * @return 结果
     */
    @Override
    public int insertRoom(Room room)
    {
        // 设置创建时间和更新时间
        LocalDateTime now = LocalDateTime.now();
        room.setCreatedAt(now);
        room.setUpdatedAt(now);
        return roomMapper.insertRoom(room);
    }

    /**
     * 修改会议室管理
     * 
     * @param room 会议室管理
     * @return 结果
     */
    @Override
    public int updateRoom(Room room)
    {
        // 只更新更新时间
        room.setUpdatedAt(LocalDateTime.now());
        return roomMapper.updateRoom(room);
    }

    /**
     * 批量删除会议室管理
     * 
     * @param roomIds 需要删除的会议室管理主键
     * @return 结果
     */
    @Override
    public int deleteRoomByRoomIds(Long[] roomIds)
    {
        return roomMapper.deleteRoomByRoomIds(roomIds);
    }

    /**
     * 删除会议室管理信息
     * 
     * @param roomId 会议室管理主键
     * @return 结果
     */
    @Override
    public int deleteRoomByRoomId(Long roomId)
    {
        return roomMapper.deleteRoomByRoomId(roomId);
    }

    @Override
    public boolean checkRoomAddressExists(String roomAddress) {
        return roomMapper.checkRoomAddressExists(roomAddress) > 0;
    }

    @Override
    public boolean checkRoomAddressExistsForUpdate(Room room) {
        return roomMapper.checkRoomAddressExistsForUpdate(room.getRoomAddress(), room.getRoomId()) > 0;
    }
}
